package com.liuyang.concurrency.chapter11;

import java.util.Arrays;

public class ThreadGroup {
    public static void main(String[] args) {
        // USE THE NAME
        java.lang.ThreadGroup tg1 = new java.lang.ThreadGroup("TG1");
        Thread t1 = new Thread(tg1,"t1"){
            @Override
            public void run() {
                while (true){
//                    System.out.println(getThreadGroup().getName());
//                    System.out.println(getThreadGroup().getParent());
                    try {
                        Thread.sleep(1_000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        };
        t1.start();

        java.lang.ThreadGroup tg2 = new java.lang.ThreadGroup("TG2");
        Thread t2 = new Thread(tg2,"T2"){
            @Override
            public void run() {
                System.out.println(tg1.getName());
                Thread[] threads = new Thread[tg1.activeCount()];
                tg1.enumerate(threads);
                Arrays.asList(threads).forEach(System.out::println);
            }
        };
        t2.start();
        //USE THE PARENT AND GROUP NAME

    }
}
